package com.xmy.cultivate.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.xmy.cultivate.entity.RadeExcludeStudent;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.views.SelectStudent;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 率排除学生 Mapper 接口
 * </p>
 *
 * @author hpiggy
 * @since 2024-07-27
 */
public interface RadeExcludeStudentMapper extends BaseMapper<RadeExcludeStudent> {

    @Select("SELECT * FROM `rade_exclude_student` WHERE FIND_IN_SET('${subjectId}', subjects_ids) > 0 AND year_part = ${yearPart} AND quarter_num = ${quarterNum} AND student_id = ${studentId} AND type = 2 AND deleted = 0 AND classify_id IN (7,8,9)")
    public List<RadeExcludeStudent> getRadeExcludeStudentList(@Param("subjectId") String subjectId,@Param("yearPart") Integer yearPart, @Param("quarterNum") Integer quarterNum, @Param("studentId") Long studentId);

    /**
     * 获取学生
     *
     * @param wrapper
     * @return
     */
    @Select(" select * from (select t1.school_id,t1.subjects_id,t1.student_id,t1.year_class_id,t1.year_part,t1.quarter_num,SUM(t1.residue_course_count) as residue_course_count,t1.year_and_quarter,t3.`name` as student_name,t3.head_img from order_detail as t1 LEFT JOIN (select * from student_for_data where deleted =0) as t2 on t1.student_id = t2.student_id and t1.subjects_id = t2.subjects_id LEFT JOIN student as t3 on t1.student_id = t3.id where t1.`status`<>2 and t1.deleted = 0 and (t2.id is not null) group by t1.year_part,t1.quarter_num,t1.school_id,t1.student_id,t1.subjects_id,t1.year_class_id) as t ${ew.customSqlSegment}")
    public IPage<SelectStudent> getRadeExcludeStudentStudent(IPage<?> page, @Param(Constants.WRAPPER) Wrapper wrapper);

}
